
   //分页插件
	function startPage(paging,total,callback,showpage,errorFunction){
	    var	page=parseInt($(paging).find("a.active").text())||1;
	    var	showpage=showpage||5;
	    var	totalpage=parseInt(total);
	    if(page>=totalpage) page=totalpage;
		var	star;
		var	offset=Math.floor(showpage/2);
	    var	end=star+showpage;
		var width=0;
	    var	banner='';
	    if(page>1){
	    	banner+="<a>首页</a>";
	    	banner+="<a>上一页</a>";
	    }else{
	    	banner+="<a class='disabled' >首页</a>";
	    	banner+="<a class='disabled' >上一页</a>";
	    }
		if(totalpage>showpage){
			if(page>offset+1){
		        banner+="<span>...</span>";
	            star=page-offset;
		        end=page+offset;	
	        }else{
		        star=1;
		        end=showpage;
	        }	
			if(page+offset>totalpage){
	    	    star=star-(page+offset-totalpage);
	    	    end=totalpage;
	        }
		}else{
			star=1;
			end=totalpage;
		}
	    
	    
	    for(var i=star;i<=end;i++){
		    if(i==page){
		    	banner+="<a  class='active'>"+i+"</a>";
		    }else{
		    	banner+="<a>"+i+"</a>";
		    } 
	    }	
	    if(totalpage>showpage&&page+offset<totalpage){
		    banner+="<span>...</span>";
	    }
	    if(totalpage>page){
		    banner+="<a>下一页</a>";
		    banner+="<a>尾页</a>";
	    }else{
	    	banner+="<a class='disabled'>下一页</a>";
		    banner+="<a class='disabled'>尾页</a>";
	    }
		banner+="<span>&nbsp;&nbsp;&nbsp;共"+totalpage+"页, 跳到</span><input type='text'  /><span>页&nbsp;&nbsp;</span><span class='button'>Go</span>";

        $(paging).empty().append(banner);
        $(paging).find("a").css({"text-decoration":"none",cursor:"pointer",border:"1px #ccc solid",color:"#000","border-radius":"2px",padding:"4px 8px",margin:"0 1px",background:"#F2F4F6"});
        $(paging).find("a.active").css({color:"#fff",background:"#4E606C"});
        $(paging).find("a.disabled").css({color:"#ccc"});
        $(paging).find("input").css({width:"30px",height:"20px","text-align":"center"});
        $(paging).find(".button").css({background:"#CCCCCC",cursor:"pointer",display:"inline-block",height:"24px",width:"24px","line-height":"24px","text-align":"center","border-radius":"2px"});
        $(paging).children().each(function(){
            width+=parseInt($(this).outerWidth());
        })
		$(paging).css({height:"30px",width:( width+showpage*2+10)+"px",margin:"0px auto"});
		callback(page);

        $(paging).find("a").each(function(index,value){
		$(this).click(function(){
	    	if(2<=index){
			    if(index<=(totalpage>=showpage?showpage:totalpage)+1){
				    $(this).addClass('active').siblings().removeClass('active');
				    startPage(paging,total,callback,showpage);
			    }else{
					if(index==(totalpage>=showpage?showpage:totalpage)+2){
						if(!$(this).hasClass('disabled')){
							$('.'+paging+' a.active').next().addClass('active').siblings().removeClass('active');
				            startPage(paging,total,callback,showpage);
						}
					}else{
						$(this).addClass('active').text(totalpage).siblings().removeClass('active');;
				        startPage(paging,total,callback,showpage);
					}
				}
		    }else{	
			    if(index==1){
					if(!$(this).hasClass('disabled')){
						$('.'+paging+' a.active').prev().addClass('active').siblings().removeClass('active');
				        startPage(paging,total,callback,showpage);
					}
				}else{
					$(this).addClass('active').text(1).siblings().removeClass('active');;
				    startPage(paging,total,callback,showpage);
				}
		    }
	    });	
		})
		$(paging).find(".button").click(function(){
			var val=$(paging).find("input").val();
			if(val==''||val<=0||val>totalpage){
				if(errorFunction==null) alert('页码不正确，请重新输入');
                else errorFunction('页码不正确，请重新输入');
			}else{
                $(paging).find("a.active").text(val);
				startPage(paging,total,callback,showpage);
			}
		});
	}
	